class Solution:
    def countAndSay(self, n: int) -> str:
        if n == 1:
            return "1"
        pre_str = self.countAndSay(n-1)
        res = ""
        for index, num in enumerate(pre_str):
            if index == 0:
                s_write, count = num, 1
            elif pre_str[index-1] != num:
                res += (str(count) + str(s_write))
                s_write, count = num, 1
            else:
                count += 1
            if index == len(pre_str) - 1:
                res += (str(count) + str(s_write))
        return res


a = Solution()
# for b in range(1, 10):
print(a.countAndSay(5))

